#pragma once

#include "znx_defs.h"
#include "znx_queue.h"
#include "znx_thread_base.h"

// the cleanup list is stack.

typedef void (*znx_cleanup_handler_pt)(void *data);

typedef struct znx_cleanup_item_s   znx_cleanup_item_t;

struct znx_cleanup_item_s {
    znx_cleanup_handler_pt          handler;
    void                            *data;
    znx_queue_t                     queue;
};


typedef struct {
    znx_queue_t                     head;
} znx_cleanup_list_t;


void znx_cleanup_list_init(znx_cleanup_list_t *list);

znx_cleanup_item_t *znx_cleanup_list_add(
    znx_cleanup_list_t *list, znx_cleanup_handler_pt handler, void *data);

void znx_cleanup_list_del(znx_cleanup_list_t *list, znx_cleanup_item_t *item);

void znx_cleanup_list_exec(znx_cleanup_list_t *list);